// pages/classHomePage/signIn/index/index.js
const app = getApp()

Page({
  data: {
    people: null,
    teacher_name: app.globalData.teacher_info['name'],
    student_name: app.globalData.student_info['name'],
    blindbox_history: [],
    idList: [],
    card: [{
      title: {
        text: "盲盒",
        color: "#272635" //字体颜色
      },
      tag: {
        text: "1小时前"
      },
      header: {
        bgcolor: "#f5f5f5",  //#f5f5f5  #fbde35
        line: true
      }
    }],
    funList: {
      'funitems': [{
          "name": "PK",
          "url": "/pages/classHomePage/pk/index/index",
          "pic_url": "/assets/wx_pic/menu_pk@3x.png"
        },
        {
          "name": "盲盒",
          "url": "/pages/classHomePage/blindbox/index/index",
          "pic_url": "/assets/wx_pic/menu_mh@3x.png"
        },
        {
          "name": "签到",
          "url": "/pages/classHomePage/signIn/index/index",
          "pic_url": "/assets/wx_pic/menu_qd@3x.png"
        },
        {
          "name": "辩论会",
          "url": "/pages/classHomePage/debate/index/index",
          "pic_url": "/assets/wx_pic/menu_blh@3x.png"
        },
        {
          "name": "抢答",
          "url": "/pages/classHomePage/qiangda/index/index",
          "pic_url": "/assets/wx_pic/menu_qd_1@3x.png"
        },
        {
          "name": "讨论",
          "url": "/pages/classHomePage/discuss/index/index",
          "pic_url": "/assets/wx_pic/menu_tl@3x.png"
        },
        {
          "name": "成员分组",
          "url": "/pages/classHomePage/group/index/index",
          "pic_url": "/assets/wx_pic/menu_zyfz@3x.png"
        },
        {
          "name": "积分",
          "url": "/pages/classHomePage/integral/index/index",
          "pic_url": "/assets/wx_pic/menu_jf@3x.png"
        },
      ]
    },
  },
  gotoBlindbox: function(){
    wx.navigateTo({
      url: '../new_index/new_index',
    })
  },

  onLoad(options) {
    let _this = this
    _this.setData({
      people:  wx.getStorageSync('people')
    })
    if(_this.data.people=='teacher'){
      let data = {
        class_name: app.globalData.banji_info.courseName,
        pageIndex: 1,
        pageSize: 10,
        teacher_account: wx.getStorageSync('account'),
      }
      let timu_id = null
      let timu_id_list = []
      app.formPost("/api/admin/blindbox/blindbox_view_history",data).then(res=>{
        res = JSON.parse(JSON.stringify(res).replace(/<[^>]*>/g, ''))
        // console.log("历史记录"+res['response'])
        for(let i=0;i<res['response']['list'].length;i++){
          timu_id = {
            text: '题目序号：'+res['response']['list'][i]['id']
          }
          timu_id_list.push(timu_id)
        }
        console.log(timu_id)
        _this.setData({
          blindbox_history: res['response']['list'],
          idList: timu_id_list
        })
      })
    }else if(_this.data.people=='student'){
      let data = {
        class_name: app.globalData.banji_info.className,
        stu_account: wx.getStorageSync('account'),
        pageIndex: 1,
        pageSize: 10,
      }
      let timu_id = null
      let timu_id_list = []
      app.formPost("/api/admin/blindbox/blindbox_view_history",data).then(res=>{
        res = JSON.parse(JSON.stringify(res).replace(/<[^>]*>/g, ''))
        for(let i=0;i<res['response']['list'].length;i++){
          timu_id = {
            text: '题目序号：'+res['response']['list'][i]['id']
          }
          timu_id_list.push(timu_id)
        }
        _this.setData({
          blindbox_history: res['response']['list'],
          idList: timu_id_list
        })
      })
    }
  },

  click_item: function (e) {
    if (e.currentTarget.dataset.url != '') {
      wx.navigateBack()
      wx.navigateTo({
        url: e.currentTarget.dataset.url,
      })
    }
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.onLoad()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})